/*
 * I2C_IO_Driver.h
 *
 *  Created on: Jan 29, 2013
 *      Author: Sarna
 */

#ifndef I2C_IO_DRIVER_H_
#define I2C_IO_DRIVER_H_

struct I2C_IO_DriverPort_t {
	unsigned char address;
	unsigned char port;
	unsigned char config;
	unsigned char input;
	unsigned char output;
};
enum PCA_PORT_INDEX {
	PCA_U7_SI_PORT_0_INDEX,
	PCA_U7_SI_PORT_1_INDEX,
	PCA_U8_SO_PORT_0_INDEX,
	PCA_U8_SO_PORT_1_INDEX,
	PCA_U10_MISC_LED_PORT_0_INDEX,
	PCA_U10_MISC_LED_PORT_1_INDEX,
	PCA_U9_PORT_0_INDEX,
	PCA_U9_PORT_1_INDEX
};
enum PCA_ADDRESSES {
	PCA_U7_SI = 0x74,
	PCA_U8_SO = 0x75,
	PCA_U10_MISC_LED = 0x76,
	PCA_U9 = 0x77
};
enum PCA9359_PORT {
	PORT_0,
	PORT_1
};
enum PCA9359_CMD {
	PCA_INPUT_PORT_0,
	PCA_INPUT_PORT_1,
	PCA_OUTPUT_PORT_0,
	PCA_OUTPUT_PORT_1,
	PCA_POLARITY_PORT_0,
	PCA_POLARITY_PORT_1,
	PCA_CONFIG_PORT_0,
	PCA_CONFIG_PORT_1
};
enum PCA9359_CONFIG_SYNTAX{
	PCA_CONFIG_SET_ALL_TO_OUTPUT,
	PCA_CONFIG_U10_P1 = 0x01,
	PCA_CONFIG_U10_P0 = 0x3C,
	PCA_CONFIG_SET_ALL_TO_INTPUT=0xFF // all set to input
};

enum SI_LED_Alm {  // U7 Port 0
	SI_1_Alm=0x01,
	SI_2_Alm=0x02,
	SI_3_Alm=0x04,
	SI_4_Alm=0x08,
	SI_5_Alm=0x10,
	SI_6_Alm=0x20,
	SI_7_Alm=0x40,
	SI_8_Alm=0x80
};
enum SI_LED_Flt {  // U7 Port 1
	SI_8_Flt=0x01,
	SI_7_Flt=0x02,
	SI_6_Flt=0x04,
	SI_5_Flt=0x08,
	SI_4_Flt=0x10,
	SI_3_Flt=0x20,
	SI_2_Flt=0x40,
	SI_1_Flt=0x80
};
enum SO_LED { // U8 Ports 0 and 1
	RL_4=0x80,
	RL_3=0x40,
	RL_2=0x20,
	RL_1=0x10,
	SO_4=0x08,
	SO_3=0x04,
	SO_2=0x02,
	SO_1=0x01
};
#define SO_LED_MASK (SO_1 | SO_2 | SO_3 | SO_4)
#define RL_LED_MASK (RL_1 | RL_2 | RL_3 | RL_4)
#define SORL_LED_MASK (SO_LED_MASK | RL_LED_MASK)

enum OSO_I2C {
	OSO__4=0x04,
	OSO__3=0x08,
	OSO__2=0x10,
	OSO__1=0x20
};
#define OSO_MASK (OSO__1 | OSO__2 | OSO__3 | OSO__4)
enum LED_MISC_1 {  // U10 Port 0
	STANDBY=0x01,
	PRIMARY=0x02,
	OSO_4=0x04,
	OSO_3=0x08,
	OSO_2=0x10,
	OSO_1=0x20,
	ALARMS = 0xC0,
	ALARM_1=0x40,
	ALARM_2=0x80
};
#define ALARM_MASK (ALARM_1 | ALARM_2)

enum LED_MISC_2 {  // U10 Port 1
	I2C_LED_BIT_UNUSED=0x01,
	I2C_LED_BIT_PANEL=0x02,
	I2C_LED_BIT_GA_SILENCE=0x04,
	I2C_LED_BIT_TROUBLE=0x08,
	I2C_LED_BIT_WARNING=0x10,
	I2C_LED_BIT_SERVICE_MODE=0x20,
	I2C_LED_BIT_SUPER=0x40,
	I2C_LED_BIT_GROUND=0x80
};
enum SO_STAT_LED {  // U9 Port 0 -- INPUT
	SO_STAT_8,
	SO_STAT_7,
	SO_STAT_6,
	SO_STAT_5,
	SO_STAT_4,
	SO_STAT_3,
	SO_STAT_2,
	SO_STAT_1
};
enum LED_DIAGNOSTICS { // U9 Port 1
	LD_6,
	LD_7,
	LD_8,
	LD_9,
	LD_10,
	LD_11,
	LD_12,
	LD_13
};

void I2CioDriver_init (void);
//void I2CioDriver_test (void);
void I2CioDriver_reset(void);
int sendCmdData(unsigned char slaveAddr, unsigned char cmd, unsigned char mask);
int readCmdData(unsigned char slaveAddr, unsigned char cmd, unsigned char * buff);

void I2C_SO_AllOff(void);
void I2C_SO_AllOn(void);
void I2C_SO_Off(unsigned char maskOSO, unsigned char maskSO);
void I2C_SO_On(unsigned char maskOSO, unsigned char maskSO);
void I2C_SO_test(void);
unsigned char I2C_SO_getSOstatus (void);

#endif /* I2C_IO_DRIVER_H_ */
